luci-base, luci-lua-runtime: adjust Lua template environment
authorJo-Philipp Wich <[email protected]>
Mon, 21 Nov 2022 11:27:28 +0000 (12:27 +0100)
committerJo-Philipp Wich <[email protected]>
Mon, 21 Nov 2022 11:27:28 +0000 (12:27 +0100)
To maintain full compatibility with the old Lua runtime, templates
rendered from a menu `template()` action must implicitly inherit the
`luci.dispatcher` namespace as scope while other indirectly included
templates must not.

Fixes: #6105
Signed-off-by: Jo-Philipp Wich <[email protected]>
modules/luci-base/ucode/dispatcher.uc
modules/luci-lua-runtime/luasrc/dispatcher.lua
modules/luci-lua-runtime/luasrc/template.lua

index c996c76af1075ce8475a31766ac29a32bf6c5e60..0644a756c2c4423186946f9bbb604dfd463312c9 100644 (file)
@@ -774,7 +774,9 @@ function render_action(fn) {
 function run_action(request_path, lang, tree, resolved, action) {
        switch (action?.type) {
        case 'template':
-               runtime.render(action.path, {});
+               render_action(() => {
+                       runtime.call('luci.dispatcher', 'render_lua_template', action.path);
+               });
                break;
 
        case 'view':
index 608b9b667439171f2c4b7add19f559ff5a47c6a3..93f7f8949bbbbcd6f8d8b0de379468f7b34e52a5 100644 (file)
@@ -354,6 +354,12 @@ function invoke_form_action(model, ...)
        _G.L.include("footer")
 end
 
+function render_lua_template(path)
+       local tpl = require "luci.template"
+
+       tpl.render(path, getfenv(1))
+end
+
 
 function call(name, ...)
        return {
index 84fb8bb3383d58c997f3021e0a02cb3f4f0d2068..b6b9af0badb8914412eb237a0e59b509b9b11b1e 100644 (file)
@@ -121,7 +121,7 @@ context.viewns = setmetatable({
        elseif key == "resource" then
                return L.config.main.resourcebase
        else
-               return rawget(tbl, key) or disp[key] or _G[key] or L[key]
+               return rawget(tbl, key) or _G[key] or L[key]
        end
 end})